package com.ryan.mms.position.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ryan.framework.dao.impl.BaseHibernateDaoSupport;
import com.ryan.framework.tag.pagination.Page;
import com.ryan.mms.position.dao.PositionDao;
import com.ryan.mms.position.model.Position;
import com.ryan.utils.StringUtil;

@Repository
public class PositionDaoImpl extends BaseHibernateDaoSupport<Position, Long> implements PositionDao<Position,Long> {

	public List<Position> findByPosition(Position position) {
		List<Position> positionList = this.find(generateCriterionList(position));
		return positionList;
	}

	public List<Position> findByPosition(Page page,Position position) {
		List<Position> positionList = this.find(page,generateCriterionList(position));
		return positionList;
	}

	public void deleteByPositionIds(List<Integer> pks) {
		// TODO Auto-generated method stub
		
	}

	public void deleteByPositionIds(String pks) {
		// TODO Auto-generated method stub
		
	}
	
	private List<Criterion> generateCriterionList(Position position){
		List<Criterion> criterionList=new ArrayList<Criterion>();
		if(!StringUtil.isNull(position.getPositionId())){
			criterionList.add(Restrictions.like("positionId", position.getPositionId()));
		}
		if(!StringUtil.isEmpty(position.getPositionName())){
			criterionList.add(Restrictions.like("positionName", position.getPositionName()));
		}
		if(!StringUtil.isNull(position.getCreator())){
			criterionList.add(Restrictions.eq("creator", position.getCreator()));
		}
		if(!StringUtil.isNull(position.getCreationDate())){
			criterionList.add(Restrictions.eq("creationDate", position.getCreationDate()));
		}
		if(null!=position.getEmployees()&&position.getEmployees().size()>0){
			criterionList.add(Restrictions.like("employees", position.getEmployees()));
		}
		return criterionList;
	}

}
